home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / CPPWKBK / CPPV2-7.CPP < prev    next >
C/C++ Source or Header  |  1992-08-25  |  803b  |  41 lines

  1. #define HEADER "C++ Problem 2.7 by Rick Conn using Borland C++"
  2.  
  3. #include <stdio.h>
  4.  
  5. class person {
  6.   char *name;
  7. public:
  8.   person (char *my_name);  // create a person with
  9.                            // a given name
  10.   void print_me(void);  // print the name of the person
  11.                         // and his address using this
  12. };
  13.  
  14. person::person (char *my_name)
  15. {
  16.   name = my_name;
  17. }
  18.  
  19. void person::print_me(void)
  20. {
  21.   printf("The name is %s\n", name);
  22.   printf("The address is %p\n", this);
  23. }
  24.  
  25. void main(void)
  26. {
  27.   printf("%s\n", HEADER);
  28.  
  29.   person ck ("Clark Kent");
  30.   person s ("Superman");
  31.   person bw ("Bruce Wayne");
  32.   person b ("Batman");
  33.   person bs ("Bjarne Stroustrop");
  34.  
  35.   ck.print_me();
  36.   s.print_me();
  37.   bw.print_me();
  38.   b.print_me();
  39.   bs.print_me();
  40. }
  41.